﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Admin_Member : System.Web.UI.Page
{
    MemberBUS memBUS = new MemberBUS();
    DataTable tbMember = new DataTable();
    DataView viewMember;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            MultiView1.ActiveViewIndex = 0;
        }
        LoadData();
    }
    private void LoadData()
    {

        tbMember = memBUS.returnAllMember();
        viewMember = new DataView(tbMember);
        viewMember.RowFilter = "M_Status=1";
        grvMember.DataSource = viewMember;
        grvMember.DataBind();
    }
    protected void grvMember_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Remove"))
        {
            bool check = memBUS.updateMemberStatus(e.CommandArgument.ToString());
            if (check)
            {
                LoadData();
            }
        }
        if (e.CommandName.Equals("ViewDetails"))
        {
            viewMember.RowFilter = "M_ID='" + e.CommandArgument.ToString() + "'";
            lblID.Text = viewMember[0]["M_ID"].ToString();
            lblName.Text = viewMember[0]["M_FullName"].ToString();
            lblBir.Text = DateTime.Parse(viewMember[0]["M_Bob"].ToString()).ToShortDateString();
            lblGender.Text = viewMember[0]["M_Gender"].ToString();
            lblPhone.Text = viewMember[0]["M_Phone"].ToString();
            lblAddress.Text = viewMember[0]["M_Address"].ToString();
            lblMail.Text = viewMember[0]["M_Mail"].ToString();
            lblUser.Text = viewMember[0]["M_UserName"].ToString();
            lblPassword.Text = viewMember[0]["M_Password"].ToString();
            MultiView1.ActiveViewIndex = 1;
        }
    }

    protected void grvMember_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grvMember.PageIndex = e.NewPageIndex;
        LoadData();
    }
    protected void lbnSearch_Click(object sender, EventArgs e)
    {
        if (txtFindValue.Value.Length > 0)
        {
            viewMember.RowFilter = "M_ID='" + txtFindValue.Value + "'";
            grvMember.DataSource = viewMember;
            grvMember.DataBind();
            
        }
    }
}